#ifndef GAME_H_INCLUDED
#define GAME_H_INCLUDED
#include <vector>
#include <iostream>
#include "quest.h"
#include "zsc.h"

class Game
{
private:
    Player* gamer;
    std::vector<Quest>* q;
    int qdb;
    void modify(Changes c)
    {
       if (c.done)
       {
            gamer->addXP(c.xp);
            gamer->changeBoredom(c.boredom);
       }
       else
       {
            gamer->addXP(-1*gamer->getXp());
       }
       gamer->Set(gamer->getAtk(),c.def);
       if ((gamer->getXp())>=(10+gamer->getLvl()))
       {
           gamer->lvlUp();
       }
       std::cout << "Nev: " <<  gamer->getName() << " Tapasztalati pont: " << gamer->getXp() << " Tamadoero: " << gamer->getAtk() << " Szint: " <<gamer ->getLvl() << std::endl;
    }
public:
    enum error
    {
        NOT_IN_RANGE,
        NAN,
        NE_NEXT,
        NO_SPELL,
        NO_SUCH_SAVE
    };

    Game(std::vector<Quest> &sq,std::string cl,int lvl, int atk, int def,
         int xp, int boredom, int abnum,std::vector<std::string> ab, int db, std::string name)
       {
            q = new std::vector<Quest>(sq);
            if (cl == "Harcos")
                gamer = new Warrior(name);
            else if (cl=="Varazslo")
                gamer = new Mage(name);
            else
                gamer = new Rogue(name);
            qdb=db;
            for(int i=0;i<q->size();++i)
            {
                q->operator[](i).setP(gamer);
            }
            gamer->Set(atk,def);
            gamer->addXP(xp);
            gamer->changeBoredom(boredom);
            gamer->setLvl(lvl);
            gamer->makeTheMatching(abnum,ab);
       }


    Game(std::vector<Quest> &sq,std::string cl,std::string name)
    {
        q = new std::vector<Quest>(sq);
        if (cl == "Harcos")
            gamer = new Warrior(name);
        else if (cl=="Varazslo")
            gamer = new Mage(name);
        else
            gamer = new Rogue(name);
        qdb=0;
        for(int i=0;i<q->size();++i)
        {
            q->operator[](i).setP(gamer);
        }
    }
    ~Game() { delete q; };
    void startJourney()
    {
        std::cout << "A jatek prologusa";

    }

    void nextQuest()
    {
            q->operator[](qdb).putText();
            q->operator[](qdb).askforType();

            modify(q->operator[](qdb).getCh());

        if (q->operator[](qdb).getjunc())
        {
            std::cout << "A kovetkezo kuldetes opcionalis, szeretned atugrani?" << std::endl;
            std::cout << "A kovetkezo kuldetesre(*) - Kihagyas(1)";
            int ch;
            std::cin >> ch;
            if (ch==1)
            {
                qdb++;
            }
        }
        qdb++;
    }

    void save()
    {
        std::ofstream f;
        std::string str = gamer->getName() + ".txt";
        f.open(str.c_str());
        f << gamer->getClass() << std::endl;
        f << gamer->getLvl() << std::endl;
        f << gamer->getAtk() << std::endl;
        f << gamer->getDef() << std::endl;
        f << gamer->getXp() << std::endl;
        f << gamer->getBoredom() << std::endl;
        f << gamer->getSpellNum() << std::endl;
        for(int i=0;i<gamer->getSpellNum();++i)
        {
            f << gamer->getSpecAbility(i).getName() << " ";
        }
        f << std::endl;
        f << qdb;
        f.close();
    }

    int getDQ()
    {
        return qdb;
    }

    int getQNumber()
    {
        return q->size();
    }
};

#endif // GAME_H_INCLUDED
